﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Windows;
using System.Configuration;

using MySql.Data.MySqlClient;
using RestSharp;
using Method = RestSharp.Method;
using System.Threading;
using static AutoTestCommunication_Service.Public;
using System.Collections.Concurrent;
using System.Windows.Media;

using NPOI.SS.Formula.Functions;

namespace AutoTestCommunication_Service
{
    public class SQL
    {

        //private static List<double> Io = new List<double>();
        //private static List<double> Ith = new List<double>();
        //private static List<double> Po = new List<double>();

        public static bool mysqlread(string 泵源SN, string REQName, out string MPC, out string V12, out string V34, out string MPC1, out string MPC2,string IP,out int Is235)
        {
            string ConnectionString = "SERVER=221.238.46.28;UID=test;PWD=test;DATABASE=test;PORT=3306;CHARSET=gbk";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    string SheetName = "bengyuan";
                    //string commandStr = "  select  Io, Vo   from  " + SheetName + "  where SerialNo LIKE  '%" + 泵源SN + "%'  ";
                    string commandStr = "  select  *   from  " + SheetName + "  where SerialNo LIKE  '%" + 泵源SN + "%' AND char_length(SerialNo)>9 ";
                    MySqlCommand MySqlCmd = new MySqlCommand(commandStr, conn);
                    MySqlDataAdapter MySqlDataAda = new MySqlDataAdapter(MySqlCmd);

                    DataSet daSet = new DataSet();
                    DataTable myDataTable = new DataTable();
                    DataRow[] myDataRow;
                    MySqlDataAda.Fill(myDataTable);
                    myDataRow = myDataTable.Select();
                    double sumI = 0;
                    string 查询列名 = "SerialNo";
                    double MPC调整 = 0;
                    List<string> list = new List<string>();
                    list.Add("SerialNo");
                    string[] 列名集合 = list.ToArray();
                    DataTable myDT = Public.Distinct(myDataTable, 列名集合);//获得不重复列名
                    DataRow[] myDR = myDT.Select();

                    List<double> 电流 = new List<double>();
                    List<double> 电压 = new List<double>();
                    if (myDR.Count() != 1 & myDR.Count() != 2 & myDR.Count() != 4 & myDR.Count() != 6 & myDR.Count() != 12)
                    {
                        MPC = "";
                        MPC1 = "";
                        MPC2 = "";
                        V12 = "";
                        V34 = "";
                        Is235 = 0;
                        string message = "泵源数量:" + myDR.Count().ToString() + "SN" + 泵源SN;
                        TraceMethodInfo(message);
                        //DigitalService.CreatLog(IP,message);
                        return false;
                    }
                    //光光效率数据源
                    List<double> Io = new List<double>();
                    List<double> Ith = new List<double>();
                    List<double> Po = new List<double>();
                    //光光效率计算值
                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        Io.Add(0); Ith.Add(0); Po.Add(0);
                    }
                    EP[IP].Io = Io; EP[IP].Ith = Ith; EP[IP].Po = Po;

                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        电流.Add(0); 电压.Add(0);
                    }
                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        string 型号 = Convert.ToString(myDR[i]["SerialNo"]).Trim();
                        string expression = " " + 查询列名 + " = '" + 型号 + "' ";
                        string sortOrder = "TestTime DESC";
                        DataRow[] DR = myDataTable.Select(expression, sortOrder);

                        string lastletter = 型号.Substring(型号.Length - 1, 1);
                        int Index;
                        Index = i;
                        //if (lastletter=="P"|| lastletter == "S")
                        //{
                        //    Index = Convert.ToInt32(型号.Substring(型号.Length - 2, 1)) - 1;
                        //}
                        //else
                        //{
                        //    Index = Convert.ToInt32(型号.Substring(型号.Length - 1, 1)) - 1;
                        //}

                        if (Index < 0 || Index > (myDR.Count() - 1))
                        {
                            MPC = "";
                            MPC1 = "";
                            MPC2 = "";
                            V12 = "";
                            V34 = "";
                            Is235 = 0;
                            TraceMethodInfo("泵源编号:" + Index.ToString());
                            string message = "泵源编号:" + Index.ToString();
                            //DigitalService.CreatLog(IP, message);
                            return false;
                        }
                        else
                        {
                            double Io_DR = Convert.ToDouble(DR[0]["Io"]);
                            double Vo_DR = Convert.ToDouble(DR[0]["Vo"]);
                            double Po_DR = Convert.ToDouble(DR[0]["Po"]);
                            double Ith_DR = Convert.ToDouble(DR[0]["Ith"]);

                            电流[Index] = Io_DR; 电压[Index] = Vo_DR;
                            EP[IP].Ith[Index] = Ith_DR;
                            EP[IP].Io[Index] = Io_DR;
                            EP[IP].Po[Index] = Po_DR;
                        }
                    }
                    //============================================================
                    double sumIth = 0; double sumIo = 0; double sumPo = 0;
                    for (int i = 0; i < EP[IP].Ith.Count; i++)
                    {
                        sumIth = sumIth + EP[IP].Ith[i];
                        sumIo = sumIo + EP[IP].Io[i];
                        sumPo = sumPo + EP[IP].Po[i];
                    }
                    double averageIo = sumIo / EP[IP].Io.Count;
                    double averageIth = sumIth / EP[IP].Ith.Count;
                    EP[IP].K0 = sumPo / (averageIo - averageIth);
                    EP[IP].Y0 = (sumPo * averageIth) / (averageIo - averageIth);
                    EP[IP].I3000 = "";
                    EP[IP].I2800 = "";
                    EP[IP].电流百分比3000 = "";
                    EP[IP].电流百分比2800 = "";
                    //============================================================
                    int BOARDID = Convert.ToInt32(EP[IP].PCBSN);
                    if (REQName == "P2352000")
                    {
                        if (电流.Count() == 2)
                        {
                            Is235 = 1;
                            if (电流[0] > 电流[1])
                            {
                                MPC = (电流[0] + MPC调整).ToString("#0.000");
                                MPC1 = (电流[0]).ToString("#0.000");
                                MPC2 = (电流[1]).ToString("#0.000");
                            }
                            else
                            {
                                MPC = (电流[1] + MPC调整).ToString("#0.000");
                                MPC1 = (电流[1]).ToString("#0.000");
                                MPC2 = (电流[0]).ToString("#0.000");
                            }
                        }
                        else if (电流.Count() == 4)
                        {
                            Is235 = 0;
                            for (int i = 0; i < 电流.Count(); i++)
                            {
                                sumI = sumI + 电流[i];
                            }

                            MPC = ((sumI / 电流.Count()) + MPC调整).ToString("#0.000");
                            MPC1 = ((sumI / 电流.Count())).ToString("#0.000");
                            MPC2 = "0";
                        }
                        else
                        {
                            MPC = "";
                            MPC1 = "";
                            MPC2 = "";
                            TraceMethodInfo("P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                        if (电压.Count() == 2)
                        {
                            Is235 = 1;
                            V12 = 电压[0].ToString("#0.0");
                            V34 = 电压[1].ToString("#0.0");
                        }
                        else if (电压.Count() == 4)
                        {
                            Is235 = 0;
                            double DV12 = 电压[0] + 电压[1];
                            double DV34 = 电压[2] + 电压[3];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else
                        {
                            Is235 = 0;
                            V12 = "";
                            V34 = "";
                            TraceMethodInfo("P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                    }
                    else if(BOARDID>405 & BOARDID<410)
                    {
                        Is235 = 0;
                        int numall = 0;
                        for (int i = 0; i < 电流.Count(); i++)
                        {
                            sumI = sumI + 电流[i];
                            if (电流[i]!=0)
                            {
                                numall++;
                            }
                        }

                        MPC = ((sumI / numall) + MPC调整).ToString("#0.000");
                        MPC1 = ((sumI / numall)).ToString("#0.000");
                        MPC2 = "0";double VV12 = 0;
                        for (int i = 0; i < 电压.Count(); i++)
                        {
                            VV12 = VV12 + 电压[i];
                        }
                        V12 = VV12.ToString("#0.0"); V34 = "0.0";
                    }
                    else
                    {
                        Is235 = 0;
                        int numall = 0;
                        for (int i = 0; i < 电流.Count(); i++)
                        {
                            sumI = sumI + 电流[i];
                            if (电流[i] != 0)
                            {
                                numall++;
                            }
                        }

                        MPC = ((sumI / numall) + MPC调整).ToString("#0.000");
                        MPC1 = ((sumI / numall)).ToString("#0.000");
                        MPC2 = "0";
                        if (电压.Count() == 1)
                        {
                            double DV12 = 电压[0];
                            V12 = DV12.ToString("#0.0");
                            V34 = "0.0";
                        }

                        else if (电压.Count() == 2)
                        {
                            double DV12 = 电压[0] + 电压[1];
                            V12 = DV12.ToString("#0.0");
                            V34 = "0.0";
                        }
                        else if (电压.Count() == 4)
                        {
                            double DV12 = 电压[0] + 电压[1];
                            double DV34 = 电压[2] + 电压[3];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else if (电压.Count() == 6)
                        {
                            double DV12 = 电压[0] + 电压[1] + 电压[2];
                            double DV34 = 电压[3] + 电压[4] + 电压[5];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else if (电压.Count() == 12)
                        {
                            double DV12 = 电压[0] + 电压[1] + 电压[2] + 电压[3] + 电压[4] + 电压[5];
                            double DV34 = 电压[6] + 电压[7] + 电压[8] + 电压[9] + 电压[10] + 电压[11];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else
                        {
                            V12 = "";
                            V34 = "";
                            TraceMethodInfo("非P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "非P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                    }
                    return true;
                    //MySqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    TraceMethodInfo(ex.Message + ex.StackTrace);
                    V12 = "0"; V34 = "0"; MPC = "0"; MPC1 = "0"; MPC2 = "0"; Is235 = 0;
                    return false;
                }
            }
        }

        public static bool mysqlreadInput(string 泵源SN, string REQName, out string MPC, out string V12, out string V34, out string MPC1, out string MPC2, string IP, out int Is235)
        {
            string ConnectionString = "SERVER=221.238.46.28;UID=test;PWD=test;DATABASE=test;PORT=3306;CHARSET=gbk";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    string SheetName = "bengyuan_copy2";
                    //string commandStr = "  select  Io, Vo   from  " + SheetName + "  where SerialNo LIKE  '%" + 泵源SN + "%'  ";
                    string commandStr = "  select  *   from  " + SheetName + "  where SerialNo LIKE  '%" + 泵源SN + "%' AND char_length(SerialNo)>9 ";
                    MySqlCommand MySqlCmd = new MySqlCommand(commandStr, conn);
                    MySqlDataAdapter MySqlDataAda = new MySqlDataAdapter(MySqlCmd);

                    DataSet daSet = new DataSet();
                    DataTable myDataTable = new DataTable();
                    DataRow[] myDataRow;
                    MySqlDataAda.Fill(myDataTable);
                    myDataRow = myDataTable.Select();
                    double sumI = 0;
                    string 查询列名 = "SerialNo";
                    double MPC调整 = 0;
                    List<string> list = new List<string>();
                    list.Add("SerialNo");
                    string[] 列名集合 = list.ToArray();
                    DataTable myDT = Public.Distinct(myDataTable, 列名集合);//获得不重复列名
                    DataRow[] myDR = myDT.Select();

                    List<double> 电流 = new List<double>();
                    List<double> 电压 = new List<double>();
                    if (myDR.Count() != 1 & myDR.Count() != 2 & myDR.Count() != 4 & myDR.Count() != 6 & myDR.Count() != 12)
                    {
                        MPC = "";
                        MPC1 = "";
                        MPC2 = "";
                        V12 = "";
                        V34 = "";
                        Is235 = 0;
                        string message = "泵源数量:" + myDR.Count().ToString() + "SN" + 泵源SN;
                        TraceMethodInfo(message);
                        //DigitalService.CreatLog(IP,message);
                        return false;
                    }
                    //光光效率数据源
                    List<double> Io = new List<double>();
                    List<double> Ith = new List<double>();
                    List<double> Po = new List<double>();
                    //光光效率计算值
                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        Io.Add(0); Ith.Add(0); Po.Add(0);
                    }
                    EP[IP].Io = Io; EP[IP].Ith = Ith; EP[IP].Po = Po;

                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        电流.Add(0); 电压.Add(0);
                    }
                    for (int i = 0; i < myDR.Count(); i++)
                    {
                        string 型号 = Convert.ToString(myDR[i]["SerialNo"]).Trim();
                        string expression = " " + 查询列名 + " = '" + 型号 + "' ";
                        string sortOrder = "TestTime DESC";
                        DataRow[] DR = myDataTable.Select(expression, sortOrder);

                        string lastletter = 型号.Substring(型号.Length - 1, 1);
                        int Index;
                        Index = i;
                        //if (lastletter=="P"|| lastletter == "S")
                        //{
                        //    Index = Convert.ToInt32(型号.Substring(型号.Length - 2, 1)) - 1;
                        //}
                        //else
                        //{
                        //    Index = Convert.ToInt32(型号.Substring(型号.Length - 1, 1)) - 1;
                        //}

                        if (Index < 0 || Index > (myDR.Count() - 1))
                        {
                            MPC = "";
                            MPC1 = "";
                            MPC2 = "";
                            V12 = "";
                            V34 = "";
                            Is235 = 0;
                            TraceMethodInfo("泵源编号:" + Index.ToString());
                            string message = "泵源编号:" + Index.ToString();
                            //DigitalService.CreatLog(IP, message);
                            return false;
                        }
                        else
                        {
                            double Io_DR = Convert.ToDouble(DR[0]["Io"]);
                            double Vo_DR = Convert.ToDouble(DR[0]["Vo"]);
                            double Po_DR = Convert.ToDouble(DR[0]["Po"]);
                            double Ith_DR = Convert.ToDouble(DR[0]["Ith"]);

                            电流[Index] = Io_DR; 电压[Index] = Vo_DR;
                            EP[IP].Ith[Index] = Ith_DR;
                            EP[IP].Io[Index] = Io_DR;
                            EP[IP].Po[Index] = Po_DR;
                        }
                    }
                    //============================================================
                    double sumIth = 0; double sumIo = 0; double sumPo = 0;
                    for (int i = 0; i < EP[IP].Ith.Count; i++)
                    {
                        sumIth = sumIth + EP[IP].Ith[i];
                        sumIo = sumIo + EP[IP].Io[i];
                        sumPo = sumPo + EP[IP].Po[i];
                    }
                    double averageIo = sumIo / EP[IP].Io.Count;
                    double averageIth = sumIth / EP[IP].Ith.Count;
                    EP[IP].K0 = sumPo / (averageIo - averageIth);
                    EP[IP].Y0 = (sumPo * averageIth) / (averageIo - averageIth);
                    EP[IP].I3000 = "";
                    EP[IP].I2800 = "";
                    EP[IP].电流百分比3000 = "";
                    EP[IP].电流百分比2800 = "";
                    //============================================================
                    int BOARDID = Convert.ToInt32(EP[IP].PCBSN);
                    if (REQName == "P2352000")
                    {
                        if (电流.Count() == 2)
                        {
                            Is235 = 1;
                            if (电流[0] > 电流[1])
                            {
                                MPC = (电流[0] + MPC调整).ToString("#0.000");
                                MPC1 = (电流[0]).ToString("#0.000");
                                MPC2 = (电流[1]).ToString("#0.000");
                            }
                            else
                            {
                                MPC = (电流[1] + MPC调整).ToString("#0.000");
                                MPC1 = (电流[1]).ToString("#0.000");
                                MPC2 = (电流[0]).ToString("#0.000");
                            }
                        }
                        else if (电流.Count() == 4)
                        {
                            Is235 = 0;
                            for (int i = 0; i < 电流.Count(); i++)
                            {
                                sumI = sumI + 电流[i];
                            }

                            MPC = ((sumI / 电流.Count()) + MPC调整).ToString("#0.000");
                            MPC1 = ((sumI / 电流.Count())).ToString("#0.000");
                            MPC2 = "0";
                        }
                        else
                        {
                            MPC = "";
                            MPC1 = "";
                            MPC2 = "";
                            TraceMethodInfo("P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                        if (电压.Count() == 2)
                        {
                            Is235 = 1;
                            V12 = 电压[0].ToString("#0.0");
                            V34 = 电压[1].ToString("#0.0");
                        }
                        else if (电压.Count() == 4)
                        {
                            Is235 = 0;
                            double DV12 = 电压[0] + 电压[1];
                            double DV34 = 电压[2] + 电压[3];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else
                        {
                            Is235 = 0;
                            V12 = "";
                            V34 = "";
                            TraceMethodInfo("P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                    }
                    else if (BOARDID > 405 & BOARDID < 410)
                    {
                        Is235 = 0;
                        for (int i = 0; i < 电流.Count(); i++)
                        {
                            sumI = sumI + 电流[i];
                        }

                        MPC = ((sumI / 电流.Count()) + MPC调整).ToString("#0.000");
                        MPC1 = ((sumI / 电流.Count())).ToString("#0.000");
                        MPC2 = "0"; double VV12 = 0;
                        for (int i = 0; i < 电压.Count(); i++)
                        {
                            VV12 = VV12 + 电压[i];
                        }
                        V12 = VV12.ToString("#0.0"); V34 = "0.0";
                    }
                    else
                    {
                        Is235 = 0;
                        int numall = 0;
                        for (int i = 0; i < 电流.Count(); i++)
                        {
                            sumI = sumI + 电流[i];
                            if (电流[i] != 0)
                            {
                                numall++;
                            }
                        }

                        MPC = ((sumI / numall) + MPC调整).ToString("#0.000");
                        MPC1 = ((sumI / numall)).ToString("#0.000");
                        MPC2 = "0";
                        if (电压.Count() == 1)
                        {
                            double DV12 = 电压[0];
                            V12 = DV12.ToString("#0.0");
                            V34 = "0.0";
                        }

                        else if (电压.Count() == 2)
                        {
                            double DV12 = 电压[0] + 电压[1];
                            V12 = DV12.ToString("#0.0");
                            V34 = "0.0";
                        }
                        else if (电压.Count() == 4)
                        {
                            double DV12 = 电压[0] + 电压[1];
                            double DV34 = 电压[2] + 电压[3];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else if (电压.Count() == 6)
                        {
                            double DV12 = 电压[0] + 电压[1] + 电压[2];
                            double DV34 = 电压[3] + 电压[4] + 电压[5];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else if (电压.Count() == 12)
                        {
                            double DV12 = 电压[0] + 电压[1] + 电压[2] + 电压[3] + 电压[4] + 电压[5];
                            double DV34 = 电压[6] + 电压[7] + 电压[8] + 电压[9] + 电压[10] + 电压[11];
                            V12 = DV12.ToString("#0.0");
                            V34 = DV34.ToString("#0.0");
                        }
                        else
                        {
                            V12 = "";
                            V34 = "";
                            TraceMethodInfo("非P2352000泵源数量:" + myDR.Count().ToString());
                            string message = "非P2352000泵源数量:" + myDR.Count().ToString();
                            //DigitalService.CreatLog(IP, message);
                        }
                    }
                    return true;
                    //MySqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    TraceMethodInfo(ex.Message + ex.StackTrace);
                    V12 = "0"; V34 = "0"; MPC = "0"; MPC1 = "0"; MPC2 = "0"; Is235 = 0;
                    return false;
                }
            }
        }
        public static bool Mysqlreadinfraredcameraarea()
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    string SheetName1 = "infraredcameraarea";
                    string commandStr1 = "  select *   from  " + SheetName1 + "  ";
                    MySqlCommand MySqlCmd1 = new MySqlCommand(commandStr1, conn);
                    MySqlDataAdapter MySqlDataAda1 = new MySqlDataAdapter(MySqlCmd1);

                    DataSet daSet1 = new DataSet();
                    DataTable myDataTable1 = new DataTable();
                    DataRow[] myDataRow1;
                    MySqlDataAda1.Fill(myDataTable1);
                    myDataRow1 = myDataTable1.Select();

                    for (int i = 0; i < myDataRow1.Count(); i++)
                    {
                        ConcurrentDictionary<int, IRAYArea> CDIRAYArea = new ConcurrentDictionary<int, IRAYArea>();
                        int ID = 0;
                        for (int j = 3; j < myDataTable1.Columns.Count; j = j + 4)
                        {
                            IRAYArea IRAYArea = new IRAYArea()
                            {
                                startX = Convert.ToInt32(myDataRow1[i][j + 0]),
                                startY = Convert.ToInt32(myDataRow1[i][j + 1]),
                                endX = Convert.ToInt32(myDataRow1[i][j + 2]),
                                endY = Convert.ToInt32(myDataRow1[i][j + 3]),
                            };

                            CDIRAYArea.TryAdd(ID, IRAYArea);
                            ID = ID + 1;
                        }
                        string name = Convert.ToString(myDataRow1[i]["Name"]).Trim();
                        IRAY DataRow1 = new IRAY()
                        {
                            ID = Convert.ToInt32(myDataRow1[i]["ID"]),
                            Name = name,
                            Describe = Convert.ToString(myDataRow1[i]["Describe"]).Trim(),
                            CDIRAYArea = CDIRAYArea
                        };
                        Public.CDIRAYClass.TryAdd(name, DataRow1);
                    }
                    return true;
                    //MySqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    return false;
                }
            }
        }
        public static bool Mysqlreadtablestructure3000()
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    //resuilt3structure
                    conn.Open();
                    string SheetName3 = "resuilt3structure";
                    string commandStr3 = "  select *   from  " + SheetName3 + "  ";
                    MySqlCommand MySqlCmd3 = new MySqlCommand(commandStr3, conn);
                    MySqlDataAdapter MySqlDataAda3 = new MySqlDataAdapter(MySqlCmd3);

                    DataSet daSet3 = new DataSet();
                    DataTable myDataTable3 = new DataTable();
                    DataRow[] myDataRow3;
                    MySqlDataAda3.Fill(myDataTable3);
                    myDataRow3 = myDataTable3.Select();
                    //======================================================================================================================================
                    for (int i = 0; i < myDataRow3.Count(); i++)
                    {
                        Tablestructureclass DataRow3 = new Tablestructureclass()
                        {
                            ID = Convert.ToInt32(myDataRow3[i]["ID"]),
                            NameC = Convert.ToString(myDataRow3[i]["NameC"]).Trim(),
                            NameE = Convert.ToString(myDataRow3[i]["NameE"]).Trim(),
                            value = Convert.ToString(myDataRow3[i]["value"]).Trim(),
                            judge = Convert.ToInt32(myDataRow3[i]["judge"]),
                            CANREAD = Convert.ToInt16(myDataRow3[i]["canread"])
                        };
                        resuilt3structure.TryAdd(i, DataRow3);
                    }

                    //resuilt4structure
                    string SheetName4 = "resuilt4structure";
                    string commandStr4 = "  select *   from  " + SheetName4 + "  ";
                    MySqlCommand MySqlCmd4 = new MySqlCommand(commandStr4, conn);
                    MySqlDataAdapter MySqlDataAda4 = new MySqlDataAdapter(MySqlCmd4);

                    DataSet daSet4 = new DataSet();
                    DataTable myDataTable4 = new DataTable();
                    DataRow[] myDataRow4;
                    MySqlDataAda4.Fill(myDataTable4);
                    myDataRow4 = myDataTable4.Select();
                    //======================================================================================================================================
                    for (int i = 0; i < myDataRow4.Count(); i++)
                    {
                        Tablestructureclass DataRow4 = new Tablestructureclass()
                        {
                            ID = Convert.ToInt32(myDataRow4[i]["ID"]),
                            NameC = Convert.ToString(myDataRow4[i]["NameC"]).Trim(),
                            NameE = Convert.ToString(myDataRow4[i]["NameE"]).Trim(),
                            value = "N/A",
                            CANREAD = Convert.ToInt16(myDataRow4[i]["CANREAD"])
                        };
                        resuilt4structure.TryAdd(i, DataRow4);
                    }
 

                    for (int i = 0; i < ListPOLOClass.Count; i++)
                    {
                        Tablestructureclass DataRow3 = new Tablestructureclass()
                        {
                            ID = i,
                            NameC = "",
                            NameE = ListCommandName[i].Trim(),
                            value = "",
                            POLO = ListPOLOClass[i].Trim()
                        };
                        luminescenceclassification3000.TryAdd(i, DataRow3);
                    }
                  
                    return true;
                    //MySqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    return false;
                }
            }
        }
        public static void MysqlInitializationRead3000(string IP, string SN)
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    string commandStr = "";
                    string SheetName = "";
                    int ID1 = 0; int ID2 = 0; int UserCount = 0;

                    //查找本设备最后一台未上传
                    SheetName = "bwtautotest.datatestresuilt3";
                    commandStr = "  select MAX(ID)  from " + SheetName + " where  设备IP = '" + IP + "' AND 是否已经上传= '否' ";

                    MySqlCommand MySqlCmd1 = new MySqlCommand(commandStr, conn);
                    MySqlDataAdapter MySqlDataAda1 = new MySqlDataAdapter(MySqlCmd1);
                    DataSet daSet1 = new DataSet();
                    DataTable myDataTable1 = new DataTable();
                    DataRow[] myDataRow1;
                    MySqlDataAda1.Fill(myDataTable1);

                    if (myDataTable1.Rows.Count > 0)
                    {
                        myDataRow1 = myDataTable1.Select();
                        if (myDataRow1.Count() > 0 & myDataRow1[0][0] != DBNull.Value)
                        {
                            ID1 = Convert.ToInt32(myDataRow1[0][0]);
                            commandStr = "   UPDATE " + SheetName + " SET  是否可以上传='是'     WHERE ID = " + ID1 + " ";
                            MySqlCommand MySqlCmd11 = new MySqlCommand(commandStr, conn);
                            MySqlCmd11.ExecuteNonQuery();
                        }
                    }

                    //查找SN最后一台未上传

                    commandStr = "  select MAX(ID)  from " + SheetName + " where  序列号 = '" + SN + "' AND 是否已经上传= '否' ";

                    MySqlCommand MySqlCmd2 = new MySqlCommand(commandStr, conn);

                    MySqlDataAdapter MySqlDataAda2 = new MySqlDataAdapter(MySqlCmd2);
                    DataSet daSet2 = new DataSet();
                    DataTable myDataTable2 = new DataTable();
                    DataRow[] myDataRow2;
                    MySqlDataAda2.Fill(myDataTable2);
                    if (myDataTable2.Rows.Count > 0)
                    {
                        myDataRow2 = myDataTable2.Select();
                        if (myDataRow2.Count() > 0 & myDataRow2[0][0] != DBNull.Value)
                        {
                            ID2 = Convert.ToInt32(myDataRow2[0][0]);
                            commandStr = "   UPDATE " + SheetName + " SET  是否可以上传='是'     WHERE ID = " + ID2 + " ";
                            MySqlCommand MySqlCmd22 = new MySqlCommand(commandStr, conn);
                            MySqlCmd22.ExecuteNonQuery();
                        }
                    }

                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    //MessageBox.Show(ex.StackTrace + ex.ToString());

                }
            }

        }
        public static void MysqlInitializationInsert3000(string IP)
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    string commandStr = "";
                    string SheetName = "";
                    ConcurrentDictionary<int, Tablestructureclass> RS1 = new ConcurrentDictionary<int, Tablestructureclass>();
                    for (int i = 0; i < resuilt3structure.Count; i++)
                    {
                        Tablestructureclass DataRow = new Tablestructureclass()
                        {
                            ID = resuilt3structure[i].ID,
                            CANREAD = resuilt3structure[i].CANREAD,
                            judge = resuilt3structure[i].judge,
                            NameC = resuilt3structure[i].NameC,
                            NameE = resuilt3structure[i].NameE,
                            POLO = resuilt3structure[i].POLO,
                            value = resuilt3structure[i].value,
                        };
                        RS1.TryAdd(i, DataRow);
                    }
                    ConcurrentDictionary<int, Tablestructureclass> RS2 = new ConcurrentDictionary<int, Tablestructureclass>();
                    for (int i = 0; i < resuilt4structure.Count; i++)
                    {
                        Tablestructureclass DataRow = new Tablestructureclass()
                        {
                            ID = resuilt4structure[i].ID,
                            CANREAD = resuilt4structure[i].CANREAD,
                            judge = resuilt4structure[i].judge,
                            NameC = resuilt4structure[i].NameC,
                            NameE = resuilt4structure[i].NameE,
                            POLO = resuilt4structure[i].POLO,
                            value = resuilt4structure[i].value,
                        };
                        RS2.TryAdd(i, DataRow);
                    }
                    ConcurrentDictionary<int, Tablestructureclass> LC = new ConcurrentDictionary<int, Tablestructureclass>();
                    for (int i = 0; i < luminescenceclassification3000.Count; i++)
                    {
                        Tablestructureclass DataRow = new Tablestructureclass()
                        {
                            ID = luminescenceclassification3000[i].ID,
                            CANREAD = luminescenceclassification3000[i].CANREAD,
                            judge = luminescenceclassification3000[i].judge,
                            NameC = luminescenceclassification3000[i].NameC,
                            NameE = luminescenceclassification3000[i].NameE,
                            POLO = luminescenceclassification3000[i].POLO,
                            value = luminescenceclassification3000[i].value,
                        };
                        LC.TryAdd(i, DataRow);
                    }

                    //RS2
                    SheetName = "bwtautotest.datatestresuilt4";
                    for (int i = 0; i < LC.Count; i++)
                    {
                        for (int j = 0; j < RS2.Count; j++)
                        {
                            string VL;
                            //第一次读取原始数值
                            if (RS2[j].CANREAD == 0)
                            {
                                VL = LC[i].POLO;
                            }
                            else if(RS2[j].CANREAD == 2)
                            {
                                RS2[j].NameE = LC[i].NameE + RS2[j].NameE;
                                DigitalService.ReadData(RS2[j].NameE, out VL, IP);//SDT2中的数据
                                RS2[j].value = VL;
                            }
                            else
                            {
                                DigitalService.ReadData( RS2[j].NameE, out VL, IP);//测试开始时间
                                RS2[j].value = VL;
                            }

                            //第二次对数据做相应改变
                            if (RS2[j].NameC == "测试结果")
                            {
                               RS2[j].value = VL == "1"?  "合格" : "不合格";

                            }
                            else
                            {
                                RS2[j].value = VL;
                            }
                        }
                        commandStr = "  insert   into    " + SheetName + " " +
                       "(" + RS2[0].NameC + "," + RS2[1].NameC + "," + RS2[2].NameC + "," + RS2[3].NameC + "," + RS2[4].NameC + "," + RS2[5].NameC + "," + RS2[6].NameC + "," + RS2[7].NameC + "," + RS2[8].NameC + "," + RS2[9].NameC + ", " +
                        "" + RS2[10].NameC + "," + RS2[11].NameC + "," + RS2[12].NameC + "," + RS2[13].NameC + "," + RS2[14].NameC + "," + RS2[15].NameC + "," + RS2[16].NameC + "," + RS2[17].NameC + "," + RS2[18].NameC + "," + RS2[19].NameC + ", " +
                        "" + RS2[20].NameC + "," + RS2[21].NameC + "," + RS2[22].NameC + "," + RS2[23].NameC + "," + RS2[24].NameC + "," + RS2[25].NameC + "," + RS2[26].NameC + "," + RS2[27].NameC + "," + RS2[28].NameC + "," + RS2[29].NameC + "," + RS2[30].NameC + "," + RS2[31].NameC + "," + RS2[32].NameC + "   )VALUES" +

                        "('" + RS2[0].value + "','" + RS2[1].value + "','" + RS2[2].value + "','" + RS2[3].value + "','" + RS2[4].value + "','" + RS2[5].value + "','" + RS2[6].value + "','" + RS2[7].value + "','" + RS2[8].value + "','" + RS2[9].value + "', " +
                        "'" + RS2[10].value + "','" + RS2[11].value + "','" + RS2[12].value + "','" + RS2[13].value + "','" + RS2[14].value + "','" + RS2[15].value + "','" + RS2[16].value + "','" + RS2[17].value + "','" + RS2[18].value + "','" + RS2[19].value + "', " +
                        "'" + RS2[20].value + "','" + RS2[21].value + "','" + RS2[22].value + "','" + RS2[23].value + "','" + RS2[24].value + "','" + RS2[25].value + "','" + RS2[26].value + "','" + RS2[27].value + "','" + RS2[28].value + "','" + RS2[29].value + "','" + RS2[30].value + "','" + RS2[31].value + "','" + RS2[32].value + "')";

                        MySqlCommand MySqlCmd2 = new MySqlCommand(commandStr, conn);
                        MySqlCmd2.ExecuteNonQuery();
                    }
                    //RS1

                    SheetName = "bwtautotest.datatestresuilt3";
                    for (int i = 0; i < RS1.Count; i++)
                    {
                        //if (RS1[i].CANREAD == 1)
                        //if (RS1[i].value == "0" )
                        //{
                        //    string VL;
                        //    MainWindow.ReadData(RS1[i].NameE, out VL, IP);
                        //    RS1[i].value = VL;
                        //}
                        //3-生产地6-产品结构12-功率计型号35-总测试结果37-是否已经上传38-是否可以上传
                        if (i != 2 & i != 5 & i != 11 & i != 34 & i != 36 & i != 37)
                        {
                            string VL;
                            DigitalService.ReadData(RS1[i].NameE, out VL, IP);
                            RS1[i].value = VL;
                        }
                    }

                    if (RS1[15].value == "1")//红光测试
                    {
                        RS1[15].value = "合格";
                    }
                    else
                    {
                        RS1[15].value = "不合格";
                    }
                    RS1[35].value = IP;

                    commandStr = "  insert   into    " + SheetName + " " +
                   "(" + RS1[0].NameC + "," + RS1[1].NameC + "," + RS1[2].NameC + "," + RS1[3].NameC + "," + RS1[4].NameC + "," + RS1[5].NameC + "," + RS1[6].NameC + "," + RS1[7].NameC + "," + RS1[8].NameC + "," + RS1[9].NameC + ", " +
                    "" + RS1[10].NameC + "," + RS1[11].NameC + "," + RS1[12].NameC + "," + RS1[13].NameC + "," + RS1[14].NameC + "," + RS1[15].NameC + "," + RS1[16].NameC + "," + RS1[17].NameC + "," + RS1[18].NameC + "," + RS1[19].NameC + ", " +
                    "" + RS1[20].NameC + "," + RS1[21].NameC + "," + RS1[22].NameC + "," + RS1[23].NameC + "," + RS1[24].NameC + "," + RS1[25].NameC + "," + RS1[26].NameC + "," + RS1[27].NameC + "," + RS1[28].NameC + "," + RS1[29].NameC + ", " +
                    "" + RS1[30].NameC + "," + RS1[31].NameC + "," + RS1[32].NameC + " ," + RS1[33].NameC + " ," + RS1[34].NameC + " ," + RS1[35].NameC + " ," + RS1[36].NameC + " ," + RS1[37].NameC + "                                                                                                                           )VALUES" +
                    "('" + RS1[0].value + "','" + RS1[1].value + "','" + RS1[2].value + "','" + RS1[3].value + "','" + RS1[4].value + "','" + RS1[5].value + "','" + RS1[6].value + "','" + RS1[7].value + "','" + RS1[8].value + "','" + RS1[9].value + "', " +
                    "'" + RS1[10].value + "','" + RS1[11].value + "','" + RS1[12].value + "','" + RS1[13].value + "','" + RS1[14].value + "','" + RS1[15].value + "','" + RS1[16].value + "','" + RS1[17].value + "','" + RS1[18].value + "','" + RS1[19].value + "', " +
                    "'" + RS1[20].value + "','" + RS1[21].value + "','" + RS1[22].value + "','" + RS1[23].value + "','" + RS1[24].value + "','" + RS1[25].value + "','" + RS1[26].value + "','" + RS1[27].value + "','" + RS1[28].value + "','" + RS1[29].value + "', " +
                    "'" + RS1[30].value + "','" + RS1[31].value + "','" + RS1[32].value + "','" + RS1[33].value + "','" + RS1[34].value + "','" + RS1[35].value + "','" + RS1[36].value + "','" + RS1[37].value + "' )";
                    MySqlCommand MySqlCmd1 = new MySqlCommand(commandStr, conn);
                    MySqlCmd1.ExecuteNonQuery();

                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    //MessageBox.Show(ex.StackTrace + ex.ToString());

                }
            }
        }
        public static void MysqlDataUpdate3000(string IP, string SN, string starttime)
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();
                    if (EP[IP].CDSDT[90].Stringvalue == "测试完成")
                    {
                        string commandStr = "";
                        string SheetName = "";
                        int ID1 = 0; int ID2 = 0;

                        //查找本设备最后一台未上传
                        SheetName = "bwtautotest.datatestresuilt3";
                        commandStr = "  select *  from " + SheetName + " where    测试开始时间 = '" + starttime + "'    AND     序列号 = '" + SN + "'    AND       设备IP = '" + IP + "' AND 是否已经上传= '否' ";

                        MySqlCommand MySqlCmd1 = new MySqlCommand(commandStr, conn);

                        MySqlDataAdapter MySqlDataAda1 = new MySqlDataAdapter(MySqlCmd1);
                        DataSet daSet1 = new DataSet();
                        DataTable myDataTable1 = new DataTable();
                        DataRow[] myDataRow1;
                        MySqlDataAda1.Fill(myDataTable1);

                        if (myDataTable1.Rows.Count > 0)
                        {
                            myDataRow1 = myDataTable1.Select();
                            if (myDataRow1.Count() > 0)
                            {
                                ID1 = Convert.ToInt32(myDataRow1[0][0]);
                                commandStr = "   UPDATE " + SheetName + " SET  是否可以上传='是'     WHERE ID = '" + ID1 + "' ";
                                MySqlCommand MySqlCmd11 = new MySqlCommand(commandStr, conn);
                                MySqlCmd11.ExecuteNonQuery();
                                string endtime = EP[IP].CDSDT[91].Stringvalue;
                                commandStr = "   UPDATE " + SheetName + " SET  测试结束时间='" + endtime + "'     WHERE ID = '" + ID1 + "' ";
                                MySqlCommand MySqlCmd12 = new MySqlCommand(commandStr, conn);
                                MySqlCmd12.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {
                        string commandStr = "";
                        string SheetName = "";
                        ConcurrentDictionary<int, Tablestructureclass> RS3 = new ConcurrentDictionary<int, Tablestructureclass>();
                        for (int i = 0; i < resuilt3structure.Count; i++)
                        {
                            Tablestructureclass DataRow = new Tablestructureclass()
                            {
                                ID = resuilt3structure[i].ID,
                                CANREAD = resuilt3structure[i].CANREAD,
                                judge = resuilt3structure[i].judge,
                                NameC = resuilt3structure[i].NameC,
                                NameE = resuilt3structure[i].NameE,
                                POLO = resuilt3structure[i].POLO,
                                value = resuilt3structure[i].value,
                            };
                            RS3.TryAdd(i, DataRow);
                        }
                        ConcurrentDictionary<int, Tablestructureclass> RS4 = new ConcurrentDictionary<int, Tablestructureclass>();
                        for (int i = 0; i < resuilt4structure.Count; i++)
                        {
                            Tablestructureclass DataRow = new Tablestructureclass()
                            {
                                ID = resuilt4structure[i].ID,
                                CANREAD = resuilt4structure[i].CANREAD,
                                judge = resuilt4structure[i].judge,
                                NameC = resuilt4structure[i].NameC,
                                NameE = resuilt4structure[i].NameE,
                                POLO = resuilt4structure[i].POLO,
                                value = resuilt4structure[i].value,
                            };
                            RS4.TryAdd(i, DataRow);
                        }
                        ConcurrentDictionary<int, Tablestructureclass> LC = new ConcurrentDictionary<int, Tablestructureclass>();
                        for (int i = 0; i < luminescenceclassification3000.Count; i++)
                        {
                            Tablestructureclass DataRow = new Tablestructureclass()
                            {
                                ID = luminescenceclassification3000[i].ID,
                                CANREAD = luminescenceclassification3000[i].CANREAD,
                                judge = luminescenceclassification3000[i].judge,
                                NameC = luminescenceclassification3000[i].NameC,
                                NameE = luminescenceclassification3000[i].NameE,
                                POLO = luminescenceclassification3000[i].POLO,
                                value = luminescenceclassification3000[i].value,
                            };
                            LC.TryAdd(i, DataRow);
                        }

                        //RS2
                        SheetName = "bwtautotest.datatestresuilt4";
                        for (int i = 0; i < LC.Count; i++)
                        {
                            if(LC[i].POLO == EP[IP].Last_POLO)
                            {
                                for (int j = 0; j < RS4.Count; j++)
                                {
                                    string VL;
                                    string Name;
                                    if (RS4[j].CANREAD == 2)
                                    {
                                        Name = LC[i].NameE + RS4[j].NameE;
                                        DigitalService.ReadData(Name, out VL, IP);
                                    }
                                    else if (RS4[j].CANREAD == 1)
                                    {
                                        Name = RS4[j].NameE;
                                        DigitalService.ReadData(Name, out VL, IP);
                                    }
                                    else if (RS4[j].CANREAD == 3)
                                    {
                                        Name = RS4[j].NameE;
                                        DigitalService.ReadData(Name, out VL, IP);
                                    }
                                    else if (RS4[j].CANREAD == 0)
                                    {
                                        VL = LC[i].POLO;
                                        if (VL == "101%" & EP[IP].电流百分比2800 != "")
                                        {
                                            VL = EP[IP].电流百分比2800;
                                        }
                                        else if (VL == "102%" & EP[IP].电流百分比3000 != "")
                                        {
                                            VL = EP[IP].电流百分比3000;
                                        }
                                    }
                                    else if (RS4[j].CANREAD == 4 & LC[i].NameE != "ST9" & LC[i].NameE != "ST10")//光光效率
                                    {
                                        double 激光功率 = 0; double 驱动电流1 = 0; double 驱动电流2 = 0;
                                        string str驱动电流1 = RS4[13].value, str驱动电流2 = RS4[14].value;

                                        if (RS4[15].value == "N/A")
                                        {
                                            VL = "N/A";
                                        }
                                        else if (str驱动电流1 == "N/A" & str驱动电流2 == "N/A")
                                        {
                                            VL = "N/A";
                                        }
                                        else if (str驱动电流1 == "" & str驱动电流2 == "")
                                        {
                                            VL = "N/A";
                                        }
                                        else if (str驱动电流1 == "0" & str驱动电流2 == "0")
                                        {
                                            VL = "N/A";
                                        }
                                        else
                                        {
                                            激光功率 = Convert.ToDouble(RS4[15].value);
                                            驱动电流1 = Convert.ToDouble(str驱动电流1);
                                            驱动电流2 = Convert.ToDouble(str驱动电流2);


                                            //string PN = EP[IP].CDSDT[46].Stringvalue;
                                            //string power = PN.Substring(6, 2);
                                            double DBVL = 0;

                                            List<double> 功率 = new List<double>();
                                            for (int k = 0; k < EP[IP].Po.Count; k++)
                                            {
                                                功率.Add(0);
                                            }
                                            int 泵源分界数 = EP[IP].Po.Count / 2;

                                            if (驱动电流1 >= 1 & 驱动电流2 >= 1)
                                            {
                                                for (int k = 0; k < EP[IP].Po.Count; k++)
                                                {
                                                    if (k < 泵源分界数)
                                                    {
                                                        if (EP[IP].Po[k] != 0 && EP[IP].Io[k] != 0)
                                                        {
                                                            功率[k] = EP[IP].Po[k] * (驱动电流1 - EP[IP].Ith[k]) / (EP[IP].Io[k] - EP[IP].Ith[k]);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (EP[IP].Po[k] != 0 && EP[IP].Io[k] != 0)
                                                        {
                                                            功率[k] = EP[IP].Po[k] * (驱动电流2 - EP[IP].Ith[k]) / (EP[IP].Io[k] - EP[IP].Ith[k]);
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (驱动电流1 >= 1)
                                                {
                                                    for (int k = 0; k < EP[IP].Po.Count; k++)
                                                    {
                                                        if (EP[IP].Po[k] != 0 && EP[IP].Io[k] != 0)
                                                        {
                                                            功率[k] = EP[IP].Po[k] * (驱动电流1 - EP[IP].Ith[k]) / (EP[IP].Io[k] - EP[IP].Ith[k]);
                                                        }
                                                    }
                                                }
                                                else if (驱动电流2 >= 1)
                                                {
                                                    for (int k = 0; k < EP[IP].Po.Count; k++)
                                                    {
                                                        if (EP[IP].Po[k] != 0 && EP[IP].Io[k] != 0)
                                                        {
                                                            功率[k] = EP[IP].Po[k] * (驱动电流2 - EP[IP].Ith[k]) / (EP[IP].Io[k] - EP[IP].Ith[k]);
                                                        }
                                                    }
                                                }
                                            }
                                            DBVL = 激光功率 / 功率.Sum();
                                            VL = DBVL.ToString("P1");
                                            int gg = Convert.ToInt32(DBVL * 1000);
                                            Public.EP[IP].GGXL = gg.ToString();
                                            if (LC[i].POLO == "70%")
                                            {
                                                double I3000 = ((3000 / DBVL) + EP[IP].Y0) / EP[IP].K0;
                                                double I2800 = ((2800 / DBVL) + EP[IP].Y0) / EP[IP].K0;
                                                EP[IP].I3000 = (I3000 * 1000).ToString("F0");
                                                EP[IP].I2800 = (I2800 * 1000).ToString("F0");
                                                string searchName = "MPC";
                                                string searchVL = "";
                                                DigitalService.ReadData(searchName, out searchVL, IP);
                                                EP[IP].电流百分比3000 = (I3000 / Convert.ToDouble(searchVL)).ToString("P1");
                                                EP[IP].电流百分比2800 = (I2800 / Convert.ToDouble(searchVL)).ToString("P1");

                                            }
                                        }
                                    }
                                    else
                                    {
                                        VL = "N/A";
                                    }

                                    if (RS4[j].NameE == "TestResult" & VL == "1")
                                    {
                                        RS4[j].value = "合格";
                                    }
                                    else if (RS4[j].NameE == "TestResult" & VL == "0")
                                    {
                                        RS4[j].value = "不合格";
                                    }
                                    else
                                    {
                                        RS4[j].value = VL;
                                    }
                                }
                                commandStr = "  Update   " + SheetName + "  SET " +
                                " " + RS4[0].NameC + "='" + RS4[0].value + "' ," + RS4[1].NameC + "='" + RS4[1].value + "' ," + RS4[2].NameC + "='" + RS4[2].value + "' ," + RS4[3].NameC + "='" + RS4[3].value + "' ,  " +
                                " " + RS4[4].NameC + "='" + RS4[4].value + "' ," + RS4[5].NameC + "='" + RS4[5].value + "' ," + RS4[6].NameC + "='" + RS4[6].value + "' ," + RS4[7].NameC + "='" + RS4[7].value + "' ,  " +
                                " " + RS4[8].NameC + "='" + RS4[8].value + "' ," + RS4[9].NameC + "='" + RS4[9].value + "' ," + RS4[10].NameC + "='" + RS4[10].value + "' ," + RS4[11].NameC + "='" + RS4[11].value + "' ,  " +
                                " " + RS4[12].NameC + "='" + RS4[12].value + "' ," + RS4[13].NameC + "='" + RS4[13].value + "' ," + RS4[14].NameC + "='" + RS4[14].value + "' ," + RS4[15].NameC + "='" + RS4[15].value + "' ,  " +
                                " " + RS4[16].NameC + "='" + RS4[16].value + "' ," + RS4[17].NameC + "='" + RS4[17].value + "' ," + RS4[18].NameC + "='" + RS4[18].value + "' ," + RS4[19].NameC + "='" + RS4[19].value + "' ,  " +
                                " " + RS4[20].NameC + "='" + RS4[20].value + "' ," + RS4[21].NameC + "='" + RS4[21].value + "' ," + RS4[22].NameC + "='" + RS4[22].value + "' ," + RS4[23].NameC + "='" + RS4[23].value + "' ,  " +
                                " " + RS4[24].NameC + "='" + RS4[24].value + "' ," + RS4[25].NameC + "='" + RS4[25].value + "' ," + RS4[26].NameC + "='" + RS4[26].value + "' ," + RS4[27].NameC + "='" + RS4[27].value + "' ,  " +
                                " " + RS4[28].NameC + "='" + RS4[28].value + "' ," + RS4[29].NameC + "='" + RS4[29].value + "' ," + RS4[30].NameC + "='" + RS4[30].value + "' ," + RS4[31].NameC + "='" + RS4[31].value + "' ," + RS4[32].NameC + "='" + RS4[32].value + "'   " +

                                " WHERE      测试开始时间 = '" + starttime + "' AND   序列号 = '" + SN + "' AND  出光百分比 = '" + EP[IP].EPListPOLOClass[i] + "' ";
                                //" WHERE   设备IP = '" + IP + "' AND   测试开始时间 = '" + starttime + "' AND   序列号 = '" + SN + "'  AND  是否已经上传='否'   ";
                                MySqlCommand MySqlCmd2 = new MySqlCommand(commandStr, conn);
                                MySqlCmd2.ExecuteNonQuery();
                               
                                if(EP[IP].EPListPOLOClass[i]=="101" & EP[IP].I2800!="")
                                {
                                    EP[IP].EPListPOLOClass[i] = EP[IP].I2800;
                                }
                                else if(EP[IP].EPListPOLOClass[i] == "102" & EP[IP].I3000 != "")
                                {
                                    EP[IP].EPListPOLOClass[i] = EP[IP].I3000;
                                }
                            }
                        }
                        //RS3
                        SheetName = "bwtautotest.datatestresuilt3";
                        for (int i = 0; i < RS3.Count; i++)
                        {
                            if (RS3[i].CANREAD == 1)
                            {
                                string VL;
                                DigitalService.ReadData(RS3[i].NameE, out VL, IP);
                                RS3[i].value = VL;
                            }
                            if (RS3[i].judge == 1 & RS3[i].value == "0")
                            {
                                RS3[i].value = "不合格";
                            }
                            else if (RS3[i].judge == 1 & RS3[i].value == "1")
                            {
                                RS3[i].value = "合格";
                            }
                        }
                        if (RS3[33].value == "合格")
                        {
                            RS3[34].value = "合格";
                        }
                        else
                        {
                            RS3[34].value = "不合格";
                        }

                        commandStr = "  Update   " + SheetName + "  SET " +
                        " " + RS3[0].NameC + "='" + RS3[0].value + "' ," + RS3[1].NameC + "='" + RS3[1].value + "' ," + RS3[2].NameC + "='" + RS3[2].value + "' ," + RS3[3].NameC + "='" + RS3[3].value + "' ,  " +
                        " " + RS3[4].NameC + "='" + RS3[4].value + "' ," + RS3[5].NameC + "='" + RS3[5].value + "' ," + RS3[6].NameC + "='" + RS3[6].value + "' ," + RS3[7].NameC + "='" + RS3[7].value + "' ,  " +
                        " " + RS3[8].NameC + "='" + RS3[8].value + "' ," + RS3[9].NameC + "='" + RS3[9].value + "' ," + RS3[10].NameC + "='" + RS3[10].value + "' ," + RS3[11].NameC + "='" + RS3[11].value + "' ,  " +
                        " " + RS3[12].NameC + "='" + RS3[12].value + "' ," + RS3[13].NameC + "='" + RS3[13].value + "' ," + RS3[14].NameC + "='" + RS3[14].value + "' ," + RS3[15].NameC + "='" + RS3[15].value + "' ,  " +
                        " " + RS3[16].NameC + "='" + RS3[16].value + "' ," + RS3[17].NameC + "='" + RS3[17].value + "' ," + RS3[18].NameC + "='" + RS3[18].value + "' ," + RS3[19].NameC + "='" + RS3[19].value + "' ,  " +
                        " " + RS3[20].NameC + "='" + RS3[20].value + "' ," + RS3[21].NameC + "='" + RS3[21].value + "' ," + RS3[22].NameC + "='" + RS3[22].value + "' ," + RS3[23].NameC + "='" + RS3[23].value + "' ,  " +
                        " " + RS3[24].NameC + "='" + RS3[24].value + "' ," + RS3[25].NameC + "='" + RS3[25].value + "' ," + RS3[26].NameC + "='" + RS3[26].value + "' ," + RS3[27].NameC + "='" + RS3[27].value + "' ,  " +
                        " " + RS3[28].NameC + "='" + RS3[28].value + "' ," + RS3[29].NameC + "='" + RS3[29].value + "' ," + RS3[30].NameC + "='" + RS3[30].value + "' ," + RS3[31].NameC + "='" + RS3[31].value + "' ,  " +
                        " " + RS3[32].NameC + "='" + RS3[32].value + "' ," + RS3[33].NameC + "='" + RS3[33].value + "' ," + RS3[34].NameC + "='" + RS3[34].value + "'  " +                                                                                                
                       " WHERE   设备IP = '" + IP + "' AND   测试开始时间 = '" + starttime + "' AND   序列号 = '" + SN + "'  AND  是否已经上传='否'   ";

                        MySqlCommand MySqlCmd1 = new MySqlCommand(commandStr, conn);
                        MySqlCmd1.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    //MessageBox.Show(ex.StackTrace + ex.ToString());

                }
            }
        }
        public static void Mysqlcameraalarm(string TestTime, string SN, string DeviceIP)
        {
            string ConnectionString = "SERVER=localhost;UID=root;PWD=testuser123456;DATABASE=bwtautotest;PORT=3306;CharSet=utf8;pooling=true;SslMode=None;";

            using (MySqlConnection conn = new MySqlConnection(ConnectionString))
            {
                try
                {
                    //连接数据库
                    conn.Open();

                        string commandStr = "";
                        string SheetName = "";

                        //收到警报通知截图程序
                        SheetName = "bwtautotest.cameraalarm";
                        commandStr = "   UPDATE " + SheetName + " SET  TestTime= '" + TestTime + "', SN= '" + SN + "', IsWarning= '是'     WHERE DeviceIP = '" + DeviceIP + "' ";

                        MySqlCommand MySqlCmd = new MySqlCommand(commandStr, conn);
                        MySqlCmd.ExecuteNonQuery();
                                       
                }
                catch (Exception ex)
                {
                     TraceMethodInfo(ex.Message+ex.StackTrace);
                    //MessageBox.Show(ex.StackTrace + ex.ToString());

                }
            }
        }

    }
}
